<template>
	<view class="page">
		<view class="bodys">
			<view class="bodys_title">
				<view class="" v-if="userInfo.shop_name">
					<text class="text">对方名称:</text>{{userInfo.shop_name}}/{{userInfo.username}}
				</view>
				<view class="" v-else>
					<text class="text">对方名称:</text>{{userInfo.username}}
				</view>
				<view class="">
					<text class="text">对方账号:</text>{{userInfo.mobile}}
				</view>
			</view>
			<view class="cont">
				<input type="text" placeholder="转账金额" v-model="money" />
			</view>
			<view class="text">
				到账金额:{{arrive_money}}
			</view>
			<view class="text">
				费率:{{userInfo.rates}}
			</view>
		</view>
		<view class="btn btn_css " @click="btn">
			确定
		</view>
		<!-- 支付密码弹窗 -->
		<uni-popup ref="pay_popup" type="bottom" border-radius="10px 10px 0 0">
			<view class="popups">
				<uni-icons type="close" size="30" @click="pay_close(0)"></uni-icons>
				<view class="popups_title" style="margin-top: -30px;color: black;font-size: 25px;">
					请输入支付密码
				</view>
				<view style="text-align: center;">
					提现
				</view>
				<view class="popus_money justify-content-center">
					<text class="popus_money_right">
						<text style="font-size: 18px;">￥</text>{{money}}
					</text>
				</view>
				<view class="popus_money_thr">
					<input type="password" placeholder="请输入密码" class="password" :maxlength="6" v-model="password">
				</view>
				<view class="btn btn_css" @click="pay_close(1)">
					确定
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getTransferAccounts
	} from '../../api/trade/index.js'
	export default {
		data() {
			return {
				userInfo: {},
				money: '',
				arrive_money: '',
				rates: '',
				password: ''
			}
		},
		onLoad() {
			this.userInfo = uni.getStorageSync("userInfo");
		},
		methods: {
			btn() {
				this.$refs.pay_popup.open('center')
			},
			pay_close(e) {
				if (e == 0) {
					this.$refs.pay_popup.close('center')
				} else {
					var data = {
						money: this.money,
						tomobile: this.userInfo.mobile,
						toname: this.userInfo.shop_name,
						pwd: this.password
					};
					this.$refs.pay_popup.close('center')
					getTransferAccounts(data).then(res => {
						uni.showToast({
							"icon": "none",
							"title": res.msg
						})
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/payouts/await'
							})
						}, 1500);
					})
				}
			},
		},
		watch: {
			money(newVaL, oldVal) {
				console.log(newVaL, oldVal);
				console.log(this.userInfo.rates);
				if (newVaL) {
					this.arrive_money = this.money - (this.money * this.userInfo.rates.toFixed(2));
					console.log(111, (this.money * this.userInfo.rates).toFixed(2));
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		.bodys {
			margin: 30rpx;
			padding: 30rpx;

			.bodys_title {
				font-size: 14px;

				.text {
					color: #b2b2b2;
				}
			}
		}

		.cont {
			background-color: white;
			margin: 20rpx 0;
			padding: 20rpx;
			border-radius: 15rpx;
		}

		.text {
			color: #b6b6b6;
			margin-top: -10rpx;
			padding: 5rpx 0;
		}

		.popups {
			background-color: white;
			width: 640rpx;
			padding: 30rpx;
			border-radius: 30rpx;

			.popups_title {
				padding: 30rpx;
				text-align: center;
				font-size: 28px;
				color: #ff4509;
				padding: 30rpx;
			}

			.popus_money_thr {
				padding: 30rpx;

				.popus_money_thr_title {
					padding: 0 0 30rpx 0;
					font-size: 16px;
				}

				.password {
					letter-spacing: 3px;
					text-align: center;
					font-size: 50rpx;
					border: 1px solid #b2b2b2;
					padding: 10rpx;
					border-radius: 15rpx;
				}
			}

			.btn_css {
				padding: 30rpx;
				border-radius: 50rpx;
			}

			.popups_text {
				line-height: 30px;
				font-size: 18px;
			}

			.btn_css {
				margin-top: 30px;
			}
		}
	}
</style>